<template>
    <view class="main">
        <!--<image class="bgimg" src="./static/icon/bg.png"></image>-->
        <view class="headwz" :style="'color:' + color">{{ xtxx.url_name }}</view>
        <image class="hdimg ab" :src="xtxx.link_logo"></image>
        <view class="resite border1">
            <view>帐号密码登录</view>
            <view class="ab udlr">
                <view class="resite_one">
                    <view class="text">
                        <view class="rel">
                            <image class="ab udlr" src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/account.png"></image>
                        </view>
                        <view>
                            <input v-model="name" placeholder="请输入账号" placeholderStyle="font-size:30rpx;" />
                        </view>
                    </view>
                </view>
                <view class="resite_one">
                    <view class="text">
                        <view class="rel">
                            <image class="ab udlr" src="./static/icon/password.png"></image>
                        </view>
                        <view>
                            <input v-model="password"  placeholder="请输入密码" />
                        </view>
                    </view>
                </view>
            </view>
            <button @tap="sign" :style="'background:' + color">登录</button>
        </view>
        <!--<button @tap="weixin" class="weui-btn">-->
        <!--    <image src="./static/icon/wxdl.png"></image>-->
        <!--    微信登录-->
        <!--</button>-->
        <view @tap="tel" class="ft">
            <view>客服电话：{{ xtxx.tel }}</view>
        </view>
    </view>
</template>

<script>

import {mutations as uniIdMutations} from '@/uni_modules/uni-id-pages/common/store.js'
// uniIdMutations.logout()

import uniImUtils from '@/uni_modules/uni-im/common/utils.js';



import cardlist from '@/ymq_canyino2o/dist/cardlist/index';
import gettel from '@/ymq_canyino2o/dist/gettel/index';
var app = getApp();
export default {
    components: {
        cardlist,
        gettel
    },
    data() {
        return {
            disabled: true,
            zh: '',
            mm: '',
            logintext: '登录',
            werchat: false,

            xtxx: {
                url_name: '',
                link_logo: '',
                tel: ''
            },

            name: '',
            password: '',
            color: ''
        };
    },
    onLoad: function (t) {
        app.globalData.setNavigationBarColor(this);
        var that = this;
        //console.log(this);
        app.globalData.util.request({
            url: 'entry/wxapp/system',
            cachetime: '0',
            success: function (t) {
                console.log(t.data);
                that.setData({
                    xtxx: t.data
                });
            }
        });
    },
    onReady: function () {},
    onShow: function () {},
    onHide: function () {},
    onUnload: function () {},
    onPullDownRefresh: function () {},
    onReachBottom: function () {},
    methods: {
        tel: function () {
            uni.makePhoneCall({
                phoneNumber: this.xtxx.tel
            });
        },

        nameFun: function (t) {
            console.log(t);
            this.setData({
                name: t.detail.value
            });
        },

        passwordFun: function (t) {
            console.log(t);
            this.setData({
                password: t.detail.value
            });
        },

        async sign(t){


            //console.log(this);
            uni.showLoading({
                title: '正在提交',
                mask: true
            });

            app.globalData.util.request({
                // url: 'entry/wxapp/StoreLogin',
                url: 'entry/wxapp/store_login_uni',
                cachetime: '0',
                data: {
                    user: this.name,
                    password: this.password,
                    deviceId:uni.getSystemInfoSync().deviceId
                },
                success: async (res)=> {
                  if(res.data.code == 0) {
                    //登录失败
                    uni.showModal({
                      title: '提示',
                      content: res.data.msg
                    });
                    return false
                  }

                  console.log(res);


                  if (null != res.data.data.account.storeid) {
                      uni.setStorageSync('sjdsjid', res.data.data.account.storeid);

                      // //先把所有登录给退出,方便后续的登录
                      // await uniIdMutations.logout()
                      // 【请注意】这里的`uniIdToken` 是一个`对象`：包含：`token`和`tokenExpired`
                      await uniImUtils.login({
                        tokenExpired:  res.data.data.dy_uni_token_expired,
                        token: res.data.data.dy_uni_token
                      })

                      uni.setStorageSync('store_is_login', true)
                      this.store_is_login = true


                      uni.reLaunch({
                          url: 'wmdd/wmdd'
                      });

                      // uni.redirectTo({
                      //     url: 'wmdd/wmdd'
                      // });
                  } else {
                      uni.showModal({
                          title: '提示',
                          content: res.data.msg
                      });
                      return false
                  }
                }
            });
        },

        weixin: function (t) {
            var o = uni.getStorageSync('users').id;
            console.log(o);
            uni.showModal({
                title: '提示',
                content: '确定使用此微信号绑定的操作员身份登录吗？',
                success: function (t) {
                    if (t.confirm) {
                        console.log('用户点击确定');
                        app.globalData.util.request({
                            url: 'entry/wxapp/StoreWxLogin',
                            cachetime: '0',
                            data: {
                                user_id: o
                            },
                            success: function (t) {

                              console.log(t);
                                if (null != t.data.id) {
                                    uni.setStorageSync('sjdsjid', t.data.id);
                                    uni.redirectTo({
                                        url: 'wmdd/wmdd'
                                    });
                                } else {
                                    uni.showModal({
                                        title: '提示',
                                        content: t.data
                                    });
                                }
                            }
                        });
                    } else {
                        if (t.cancel) {
                            console.log('用户点击取消');
                        }
                    }
                }
            });
        }
    }
};
</script>
<style>
@import './login.css';
</style>
